import os
import sys
import time
import unittest
from test_cases.test_demo import Demo, TestStringMethods
from HTMLTestRunner import HTMLTestRunner

# 方法一：
# unittest.main(verbosity=0)
# 方法二：
# 创建一个测试套件，testsuite，将指定测试用例添加到测试套件里，针对方法
# suite = unittest.TestSuite()
# suite.addTest(Demo("test04"))
# suite.addTest(TestStringMethods("test_abc"))
# unittest.TextTestRunner(verbosity=2).run(suite)
# 方法三： 针对类
# suite1 = unittest.TestLoader().loadTestsFromTestCase(Demo)
# suite = unittest.TestSuite([suite1])
# unittest.TextTestRunner(verbosity=2).run(suite)
# 方法四： 针对文件路径
test_dir = "./test_cases"
discover = unittest.defaultTestLoader.discover(test_dir, pattern="test_*.py")
# unittest.TextTestRunner(verbosity=2).run(discover)

## 测试报告
path1 = os.path.split(sys.path[0])[0]

times = time.strftime("%Y%m%d%H%M%S")
report_file = path1 + "/report/" + times + "-testweb.html"
fp = open(report_file, "wb")

runner = HTMLTestRunner(stream=fp,
                        title="自动化测试报告",
                        description="运行环境：linux Chrome；运行结果受服务器网络影响，仅供参考",
                        retry=1,
                        save_last_try=True)
runner.run(discover)
